//
//  Workbench2View.m
//  DJS
//
//  Created by 浪尖渝力 on 2018/2/10.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "Workbench2View.h"
#import "BalancePaymentsViewController.h"
#import "AJWTViewController.h"
#import "NewsViewController.h"
#import "DocumentListViewController.h"
@implementation Workbench2View

-(void)creatView{
    self.backgroundColor=_LightGrey;
    _scrollView=[UIScrollView new];
    [self addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    _scrollView.scrollsToTop =NO;
    
    _scrollView.showsVerticalScrollIndicator = FALSE;
    _scrollView.showsHorizontalScrollIndicator = FALSE;
    _scrollView.bounces = NO;
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.viewController.automaticallyAdjustsScrollViewInsets = NO;
    }
      _scrollView.contentSize = CGSizeMake(0,680);
    
    UIView *topView=[UIView new];
    [_scrollView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(NAV_HEIGHT+10);
        make.width.mas_equalTo(_mainW-30);
        make.height.mas_equalTo(260);
    }];
    [self creatTopView:topView];
    
    UIView *renWuView=[UIView new];
    [_scrollView addSubview:renWuView];
    [renWuView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(topView.mas_bottom).mas_equalTo(15);
        make.width.mas_equalTo(_mainW);
        make.height.mas_equalTo(60);
    }];
    renWuView.backgroundColor=[UIColor whiteColor];
    [self creatRenWuView:renWuView];
    
    UIView *AnJianView=[UIView new];
    [_scrollView addSubview:AnJianView];
    [AnJianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(renWuView.mas_bottom).mas_equalTo(15);
        make.width.mas_equalTo(_mainW);
        make.height.mas_equalTo(142);
    }];
    AnJianView.backgroundColor=[UIColor whiteColor];
    [self creatGongZuoView:AnJianView];
}

-(void)creatTopView:(UIView *)topView{
    UIImageView *imageView=[UIImageView new];
    [topView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.bottom.mas_equalTo(0);
    }];
    imageView.layer.cornerRadius=10;
    imageView.image=[UIImage imageNamed:@"卡"];
    
    UILabel *timeLable=[UILabel new];
    [topView addSubview:timeLable];
    [timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(15);
    }];
    timeLable.textColor=[UIColor whiteColor];
    timeLable.font=[UIFont systemFontOfSize:20];
    NSString *xinQi=[self weekdayStringFromDate:[NSDate new]];
    NSString *mmDD=[ZQTools changeTimeCuo:@"mm-dd" :[ZQTools NSDateToTimeCuo:[NSDate new]]];
    timeLable.text=[NSString stringWithFormat:@"%@  %@",mmDD,xinQi];
    
 
    UILabel *label=[UILabel new];
    [topView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(80);
    }];
    label.text=@"余额（元）";
    label.font=[UIFont systemFontOfSize:18];
    label.textColor=[UIColor whiteColor];
    
    NSNumber *waiter_balance=[_userDic objectForKey:@"waiter_balance"];
    CGSize size=[ZQTools getNSStringWeight:[NSString stringWithFormat:@"%@",waiter_balance] andViewWight:30 andFont:24];
    UILabel *label2=[UILabel new];
    [topView addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(label.mas_bottom).mas_equalTo(20);
        make.width.mas_equalTo(size.width+20);
    }];
    label2.text=[NSString stringWithFormat:@"%@",waiter_balance];
    label2.textColor=[UIColor whiteColor];
    label2.font=[UIFont systemFontOfSize:24];
    
    UILabel *ChaKanLabel=[UILabel new];
    [topView addSubview:ChaKanLabel];
    [ChaKanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label2.mas_right).mas_equalTo(15);
        make.bottom.mas_equalTo(label2);
    }];
    ChaKanLabel.text=@"查看明细";
    ChaKanLabel.font=[UIFont systemFontOfSize:14];
    ChaKanLabel.textColor=[UIColor whiteColor];
    ChaKanLabel.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chanKan:)];
    [ChaKanLabel addGestureRecognizer:tapGesture];

}
//-(void)ceatAnJianView:(UIView *)topView{
//
//    topView.userInteractionEnabled=YES;
//    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectZhuangTai:)];
//    [topView addGestureRecognizer:tapGesture];
//    UIImageView *iamgeView=[UIImageView new];
//    [topView addSubview:iamgeView];
//    [iamgeView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(20);
//        make.centerY.mas_equalTo(0);
//        make.height.mas_equalTo(25);
//        make.width.mas_equalTo(18);
//    }];
//    iamgeView.image=[UIImage imageNamed:@"案件委托"];
//
//    UILabel *label=[UILabel new];
//    [topView addSubview:label];
//    [label mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(iamgeView.mas_right).mas_equalTo(15);
//        make.centerY.mas_equalTo(0);
//    }];
//    label.text=@"案件委托";
//    label.font=[UIFont systemFontOfSize:18];
//    label.textColor=ColorWithRGB(29, 29, 29);
//
//    UIImageView *jianTou=[UIImageView new];
//    [topView addSubview:jianTou];
//    [jianTou mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(-10);
//        make.centerY.mas_equalTo(0);
//        make.width.mas_equalTo(10);
//        make.height.mas_equalTo(15);
//    }];
//    jianTou.image=[UIImage imageNamed:@"iconfont-fanhui-拷贝-3"];
//
//}

-(void)creatRenWuView:(UIView *)topView{
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pusToRenWu:)];
    [topView addGestureRecognizer:tapGesture];
    UIImageView *iamgeView=[UIImageView new];
    [topView addSubview:iamgeView];
    [iamgeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(18);
    }];
    iamgeView.image=[UIImage imageNamed:@"任务"];
    UILabel *label=[UILabel new];
    [topView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(iamgeView.mas_right).mas_equalTo(15);
        make.centerY.mas_equalTo(0);
    }];
    label.text=@"任务";
    label.font=[UIFont systemFontOfSize:18];
    label.textColor=ColorWithRGB(29, 29, 29);
    
    UIView *dianView=[UIView new];
    [topView addSubview:dianView];
    [dianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(100);
        make.width.height.mas_equalTo(4);
    }];
    dianView.layer.cornerRadius=2;
    dianView.backgroundColor=[UIColor redColor];
    
    UIImageView *iamgeView2=[UIImageView new];
    [topView addSubview:iamgeView2];
    [iamgeView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(36);
        make.height.mas_equalTo(24);
    }];
    iamgeView2.image=[UIImage imageNamed:@"更多"];
    
}

-(void)creatGongZuoView:(UIView *)topView{
    
    UIView *view=[UIView new];
    [topView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    UIView *xianView4=[UIView new];
    [topView addSubview:xianView4];
    [xianView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(view.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    xianView4.backgroundColor=_LightGrey;
    
    UIView *view2=[UIView new];
    [topView addSubview:view2];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(90);
    }];
    
    UIView *xianView=[UIView new];
    [view addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(3);
    }];
    xianView.backgroundColor=_backgroundColor;
    
    UILabel *label=[UILabel new];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(xianView.mas_right).mas_equalTo(15);
        make.centerY.mas_equalTo(0);
    }];
    label.text=@"工作";
    label.textColor=ColorWithRGB(29, 29, 29);
    label.font=[UIFont systemFontOfSize:18];
    
    NSArray *nameArr=[NSArray arrayWithObjects:@"案件委托",@"个性服务", nil];
    int index=0;
    for (int i=0; i<2; i++) {
    
        UIView *beiJingView=[UIView new];
        [view2 addSubview:beiJingView];
        [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(i*(_mainW)/2);
            make.width.mas_equalTo((_mainW)/2);
            make.top.mas_equalTo(0);
            make.height.mas_equalTo(90);
        }];
        
        beiJingView.userInteractionEnabled=YES;
        beiJingView.tag=index;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectZhuangTai:)];
        [beiJingView addGestureRecognizer:tapGesture];
        
        UIImageView *image=[UIImageView new];
        [beiJingView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.centerX.mas_equalTo(-50);
            make.width.height.mas_equalTo(40);
        }];
        image.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@1",nameArr[index]]];
        
        UILabel *label=[UILabel new];
        [beiJingView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(image);
            make.left.mas_equalTo(image.mas_right).mas_equalTo(20);
        }];
        label.text=nameArr[index];
        label.textColor=ColorWithRGB(49, 49, 49);
        label.font=[UIFont systemFontOfSize:16];
        index+=1;
    }

    UIView *xianView2=[UIView new];
    [view2 addSubview:xianView2];
    [xianView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(1);
    }];
    xianView2.backgroundColor=_LightGrey;
    
    
}
-(void)pusToRenWu:(UITapGestureRecognizer *)tap{
    NewsViewController *viewContro=[[NewsViewController alloc] init];
     viewContro.message_type=@"1";
    [ZQTools pushNextViewController:self.viewController andRootController:viewContro];
}

-(void)chanKan:(UITapGestureRecognizer *)tap{
    BalancePaymentsViewController *af=[[BalancePaymentsViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:af];
}

-(void)selectZhuangTai:(UITapGestureRecognizer *)tap{
    if (tap.view.tag==0) {
        AJWTViewController *lawList=[[AJWTViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:lawList];
    }if (tap.view.tag==1) {
        DocumentListViewController *lawList=[[DocumentListViewController alloc] init];
        lawList.business_type=@"2";
        [ZQTools pushNextViewController:self.viewController andRootController:lawList];
    }
   
    
}
- (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"Sunday", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSWeekdayCalendarUnit;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}
@end
